<div id="content-header">
    <h1><?php echo __d('system','List Term');?></h1>
</div>
<div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-th-list"></i> <?php echo __d('system','Home');?></a>    
</div>
<div class="container-fluid">
<div class="row-fluid">
</div>
<div class="row-fluid">
    <div class="span12">
        <?php
            echo $this->Form->create('Term', array('id' => 'paginate','class'=>'form-horizontal', 'action' => 'edit', 'url' => $this->request->here(false), 'type' => 'file',
                'inputDefaults' => array('label' => false, 'format' => array('before', 'label', 'between', 'input', 'after', 'error'))));
            echo $this->element('toolbar');
        ?>									
        <div class="widget-box">
            <?php

                $fieldsets['type_id'] = $this->Form->input('type_id', array(
                    'label' => array('class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'value' => $typeId,
                    'type' => 'hidden'));
                $fieldsets['name'] = $this->Form->input('name', array(
                    'label' => array('text'=>__d('system','Name'),'class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'type' => 'text'));

                $fieldsets['parent_id'] = $this->Form->input('parent_id', array(
                    'label' => array('class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'type' => 'select',
                    'options' => $menus,
                    'empty' => '-- None --',
                    'escape' => false));
                $listSubSite = array(); 
                $listSubSite = Configure::read('App.themes.listSubSite'); 
                $fieldsets['sub_site'] =  $this->Form->input('sub_site', array(
                    'label' => array('text'=>__d('system','Subsite'),'class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'type' => 'select',
                    'options' => $listSubSite,
                    'empty' => __d('system',' ---- Choose Subsite ----'),
                    'escape' => false));
                $fieldsets['alias'] = $this->Form->input('alias', array(
                    'label' => array('text'=>__d('system','Alias'),'class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'type' => 'text'));                           
                    $fieldsets['action'] = $this->Form->input('action', array(
                    'label' => array('text'=>__d('system','Choose Action'),'class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'options'=>$listAction,
                    'empty'=>__d('system','-----Select Action-----'),       
                    'type' => 'select'));       
                $fieldsets['description'] = $this->Form->input('description', array(
                    'label' => array('text'=>__d('system','Description'),'class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'type' => 'textarea'));
                $fieldsets['image'] = $this->Form->input('image', array(
                    'label' => array('text'=>__d('system','Image'),'class' => 'control-label'),
                    'between' => '<div class="controls">',
                    'div' => array('class' => 'control-group'),
                    'after' => '</div>',
                    'type' => 'file'));    
            ?>      

            <?php
                echo $this->Layout->form($_layouts, $fieldsets);
            ?>
            <!--For add more gallery-->
            <label for="NodeFieldProjectImage" style="padding-left: 10px; font-weight: bold;"><?php echo __d("system", "Image Relation")?></label>
            <br />
            <span style="padding-left: 10px;"><?php echo __d("system", "Size: 900x470")?></span>
            <div class="rowset clearfix project-image">
                <div class="column coldouble">
                    <?php echo $this->Form->input('ProImage', array(
                        'label' => false,
                        'type'  => 'file', 
                        'name' => 'data[ProImage][]'));?>
                </div>
            </div>
            <div id="cloneImage"></div>
            <a style="padding-left: 10px; clear: both; display: block;" href="javascript:add_more();"><?php echo __d("system", "Add more image")?></a>                
            <!--End-->
            <!--For show list image-->
            <?php if(!empty($galleries)):?>            
                <?php 
                    foreach($galleries as $key=> $image):                        
                        if(!empty($image)):                        
                            $thumbnail_name = $image; 
                            endif;            
                    ?>
                    <span style="padding-top: 15px; display: block; float: left;">
                        <a id="image_<?php echo $key;?>" href=""><?php echo $this->Html->image($thumbnail_name, array('width'=>'100', 'height'=>'100', 'alt'=> 'Image','style'=>'width:100px !important;height:100px !important'));?></a>

                        <a id="image_del_<?php echo $key;?>" href="javascript:void(0);" onclick="delete_image('<?php echo $key?>');"><?php echo __d("system", "Delete")?></a>
                    </span>
                    <?php endforeach;?>                       
                <?php endif;?>
            <!--End-->
        </div>	
        <?php
            echo $this->Form->hidden('Paginate.task', array('id' => 'task', 'value' => ''));
            echo $this->Form->end();
        ?>        								
    </div>	
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
    $('<span>Size: 1600x850</span>').insertAfter("#NodeFieldBackgroundImage");
    $('<span>Enter a valid number: (int)</span>').insertAfter("#NodeFieldBackgroundPiority");
    $('#NodeFieldNewPostDate').datetimepicker({
        dateFormat: 'yy-mm-dd',
        timeFormat: 'hh:mm'
    });
});
function add_more(){
    var element= jQuery("#cloneImage").prev();
    jQuery(element).clone().insertBefore("#cloneImage");
    var $this = Green.Elfinder;
    jQuery('form input.file-upload').prop('readonly' , true).click(function(){
                $this.show(jQuery(this));
            });
}
function delete_image(id){
    if (confirm("Are you sure you want to delete?")) {
        var href= "<?php echo '/node/node/delete_image/'?>"+id;
        jQuery.ajax({
          url: href,
          type: "GET",
          success: function(data) {           
            jQuery('#image_'+id).remove();
            jQuery('#image_del_'+id).remove();
            //alert('Load was performed.');
          }
        });
    }
}
</script>